<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRD Form</title>
</head>
<body>
<h1>Submit CRD Data</h1>
<form id="crdForm">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required><br><br>

    <label for="spec">Spec:</label>
    <textarea id="spec" name="spec" required></textarea><br><br>

    <label for="status">Status:</label>
    <input type="text" id="status" name="status" required><br><br>

    <button type="submit">Submit</button>
</form>

<script>
    document.getElementById('crdForm').addEventListener('submit', function(event) {
        event.preventDefault();

        const formData = new FormData(event.target);
        const jsonData = {};
        formData.forEach((value, key) => {
            jsonData[key] = value;
        });

        fetch('htpp://localhost:8080/submit', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(jsonData)
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('Data submitted successfully!');
                    window.location.href = '/success';
                } else {
                    alert('Failed to submit data!');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('An error occurred!');
            });
    });
</script>
</body>
</html>